

layui.config({
    base: '/static/js/layuiModulesEX/'
});
layui.use(['paging','form'], function() {
    var $ = layui.jquery,
        paging = layui.paging(),
        layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
        layer = layui.layer, //获取当前窗口的layer对象
        form = layui.form();
    console.log(admin.schoolid);

    //联动对象
    var linkage = {};
    //渲染下拉框
    linkage.formRender = function (obj, tip) {
        $(obj).empty();
        $(obj).append('<option value="">' + tip + '</option>');
        form.render('select');
    };
    // 初始无数据存在，不可进行更改，只赋值
    linkage.read = function (obj, url) {
        // $(obj).empty();
        axios.get(url)
            .then(function (res) {
                var array = res.data.data;
                var html = '';
                for (var i in array) {
                    html += '<option value=' + array[i].id + '>' + array[i].name + '</option>';
                }
                $(obj).append(html);
                form.render('select');
                // console.log(init);
                // if (init)
                //     $(obj).next().find('[lay-value="' + id + '"]').click();
            })
            .catch(function (res) {
                console.log(res);
            });
    };

    var department = 'form select[name=department]',
        major = 'form select[name=major]',
        clazz = 'form select[name=clazz]';

    if($(department).length){
        linkage.formRender(department,'选择系');
        linkage.read(department,'/department/findBath/'+admin.schoolid);
        if($(major).length){
            linkage.formRender(major,'选择专业');
            form.on('select(department)',function (data) {
                // console.log(data);
                linkage.formRender(major,'选择专业');
                linkage.formRender(clazz,'选择班级');
                linkage.read(major,'/major/findBath/'+data.value);
            });
            if($(clazz).length){
                linkage.formRender(clazz,'选择班级');
                form.on('select(major)',function (data) {
                    // console.log(data);
                    linkage.formRender(clazz,'选择班级');
                    linkage.read(clazz,'/class/findBatchByMajorid/'+data.value);
                });
            }
        }
    }


    paging.init({
        openWait: true,
        url:'/employmentinfo/findBatchByCondition',
        elem: '#content', //内容容器
        params: { //发送到服务端的参数
            schoolid:admin.schoolid
            // valid:1
        },
        contentType : "application/json; charset=utf-8",
        type: 'POST',
        tempElem: '#tpl', //模块容器
        pageConfig: { //分页参数配置
            elem: 'paged', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
            //alert('渲染成功');
        },
        fail: function(msg) { //获取数据失败的回调
            //alert('获取数据失败')
        },
        complate: function() { //完成的回调
            //alert('处理完成');

            //绑定所有编辑按钮事件
            // $('#content').children('tr').each(function() {
            //     //获取每行记录的id值
            //     var $that = $(this).children('td:last-child');
            //     var id = $that.children('a[data-opt=more]').data('id');
            //     console.log(id);
            //     $that.children('a[data-opt=more]').on('click', function() {
            //         vm.show = false;
            //         axios.get('/employmentinfo/findDetailById/'+id)
            //             .then(function (response) {
            //                 console.log(response.data.data);
            //                 vm.employ = response.data.data;
            //             })
            //             .catch(function (response) {
            //                 console.log(response);
            //             });
            //
            //     });
            //
            //
            // });

        }
    });
    var vm = new Vue({
        el:'#Vue',
        data:{
            show:true,
            employ:{
                publisherid:publisherid
            }
        },
        methods:{
            /**
             * 筛选按钮
             */
            select:function () {
                var department = $('#department').val();
                var major = $('#major').val();
                var clazz = $('#clazz').val();
                var isEmployed = $('#isEmployed').val();
                var data = {majorid:major,classid:clazz,employed:isEmployed};
                console.log(data);
                paging.get({majorid:major,classid:clazz,employed:isEmployed,schoolid:admin.schoolid});
            },
            /**
             * 重置
             */
            reset:function () {
                linkage.formRender(major,'选择专业');
                form.render('select');
                paging.get({majorid:'',classid:'',employed:'',schoolid:admin.schoolid});
            }
        }
    });





});